home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / enscript.4 / enscript / enscript-1.4.0 / afmlib / afm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-24  |  10.1 KB  |  431 lines

  1. /* 
  2.  * Public header file.
  3.  * Copyright (c) 1995 Markku Rossi.
  4.  *
  5.  * Author: Markku Rossi <mtr@iki.fi>
  6.  */
  7.  
  8. /*
  9.  * This file is part of the AFM library.
  10.  * 
  11.  * This library is free software; you can redistribute it and/or
  12.  * modify it under the terms of the GNU Library General Public
  13.  * License as published by the Free Software Foundation; either
  14.  * version 2 of the License, or (at your option) any later version.
  15.  *
  16.  * This library is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19.  * Library General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU Library General Public
  22.  * License along with this library; if not, write to the Free
  23.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25.  
  26. #ifndef AFM_H
  27. #define AFM_H
  28.  
  29. #ifndef __P
  30. #if PROTOTYPES
  31. #define __P(protos) protos
  32. #else /* no PROTOTYPES */
  33. #define __P(protos) ()
  34. #endif /* no PROTOTYPES */
  35. #endif
  36.  
  37. /**********************************************************************
  38.  *
  39.  *     AFM file entities.
  40.  *
  41.  **********************************************************************/
  42.  
  43. /* AFM types. */
  44.  
  45. #define AFM_TYPE_STRING        1
  46. #define AFM_TYPE_NAME        2
  47. #define AFM_TYPE_NUMBER        3
  48. #define AFM_TYPE_INTEGER    4
  49. #define AFM_TYPE_ARRAY        5
  50. #define AFM_TYPE_BOOLEAN    6
  51.  
  52. typedef char *AFMString;
  53. typedef char *AFMName;
  54. typedef double AFMNumber;
  55. typedef long AFMInteger;
  56.  
  57. typedef enum 
  58. {
  59.   AFMFalse = 0,
  60.   AFMTrue = 1
  61. } AFMBoolean;
  62.  
  63. typedef struct afm_array_st *AFMArray;
  64.  
  65. struct afm_node_st
  66. {
  67.   int type;
  68.  
  69.   union
  70.     {
  71.       AFMString string;
  72.       AFMName name;
  73.       AFMNumber number;
  74.       AFMInteger integer;
  75.       AFMArray array;
  76.       AFMBoolean boolean;
  77.     } u;
  78. };
  79.  
  80. typedef struct afm_node_st AFMNode;
  81.  
  82. struct afm_array_st
  83. {
  84.   AFMNumber num_items;
  85.   AFMNode *items;
  86. };
  87.  
  88.  
  89. /* AFM file data structures. */
  90.  
  91. /*
  92.  * Sorry!  I know that those mixed case variable names are ugly,
  93.  * but this is the way how they are written in Adobe's document 
  94.  * so I think that this is the best way for documentary reasons.
  95.  */
  96.  
  97. /* Global Font Information*/
  98. struct global_font_information_st
  99. {
  100.   AFMString FontName;
  101.   AFMString FullName;
  102.   AFMString FamilyName;
  103.   AFMString Weight;
  104.   AFMNumber FontBBox_llx;
  105.   AFMNumber FontBBox_lly;
  106.   AFMNumber FontBBox_urx;
  107.   AFMNumber FontBBox_ury;
  108.   AFMString Version;
  109.   AFMString Notice;
  110.   AFMString EncodingScheme;
  111.   AFMInteger MappingScheme;
  112.   AFMInteger EscChar;
  113.   AFMString CharacterSet;
  114.   AFMInteger Characters;
  115.   AFMBoolean IsBaseFont;
  116.   AFMNumber VVector_0;
  117.   AFMNumber VVector_1;
  118.   AFMBoolean IsFixedV;
  119.   AFMNumber CapHeight;
  120.   AFMNumber XHeight;
  121.   AFMNumber Ascender;
  122.   AFMNumber Descender;
  123.   AFMArray BlendAxisTypes;
  124.   AFMArray BlendDesignPositions;
  125.   AFMArray BlendDesignMap;
  126.   AFMArray WeightVector;
  127. };
  128.  
  129. typedef struct global_font_information_st AFMGlobalFontInformation;
  130.  
  131.  
  132. /* Writing Direction Metrics. */
  133. struct writing_direction_metrics_st
  134. {
  135.   AFMBoolean is_valid;
  136.   AFMNumber UnderlinePosition;
  137.   AFMNumber UnderlineThickness;
  138.   AFMNumber ItalicAngle;
  139.   AFMNumber CharWidth_x;
  140.   AFMNumber CharWidth_y;
  141.   AFMBoolean IsFixedPitch;
  142. };
  143.  
  144. typedef struct writing_direction_metrics_st AFMWritingDirectionMetrics;
  145.  
  146.  
  147. /* Multiple Master Axis Information. */
  148. struct multiple_master_axis_info_st
  149. {
  150.   AFMString AxisType;
  151.   AFMString AxisLabel;
  152. };
  153.  
  154. typedef struct multiple_master_axis_info_st AFMMultipleMasterAxisInformation; 
  155.  
  156.  
  157. /* Individual Character Metrics. */
  158.  
  159. struct ligature_st
  160. {
  161.   AFMName successor;
  162.   AFMName ligature;
  163. };
  164.  
  165. typedef struct ligature_st AFMLigature;
  166.  
  167. /* Single individual character. */
  168. struct individual_character_metrics_st
  169. {
  170.   AFMInteger character_code;    /* default charcode (-1 if not encoded) */
  171.   AFMNumber w0x;        /* character width x in writing direction 0 */
  172.   AFMNumber w0y;        /* character width y in writing direction 0 */
  173.   AFMNumber w1x;        /* character width x in writing direction 1 */
  174.   AFMNumber w1y;        /* character width y in writing direction 1 */
  175.   AFMName name;            /* character name */
  176.   AFMNumber vv_x;        /* local VVector x */
  177.   AFMNumber vv_y;        /* local VVector y */
  178.   
  179.   /* character bounding box. */
  180.   AFMNumber llx;
  181.   AFMNumber lly;
  182.   AFMNumber urx;
  183.   AFMNumber ury;
  184.  
  185.   AFMNumber num_ligatures;
  186.   AFMLigature *ligatures;
  187. };
  188.  
  189. typedef struct individual_character_metrics_st AFMIndividualCharacterMetrics;
  190.  
  191.  
  192. /* Kerning Data. */
  193.  
  194. /* Track Kerning Data. */
  195. struct track_kern_st
  196. {
  197.   AFMInteger degree;
  198.   AFMNumber min_ptsize;
  199.   AFMNumber min_kern;
  200.   AFMNumber max_ptsize;
  201.   AFMNumber max_kern;
  202. };
  203.  
  204. typedef struct track_kern_st AFMTrackKern;
  205.  
  206.  
  207. /* Pair-Wise Kerning. */
  208. struct pair_wise_kerning_st
  209. {
  210.   AFMName name1;
  211.   AFMName name2;
  212.   AFMNumber kx;
  213.   AFMNumber ky;
  214. };
  215.  
  216. typedef struct pair_wise_kerning_st AFMPairWiseKerning;
  217.  
  218.  
  219. /* Composite fonts. */
  220.  
  221. /* Single composite component. */
  222. struct composite_component_st
  223. {
  224.   AFMName name;
  225.   AFMNumber deltax;
  226.   AFMNumber deltay;
  227. };
  228.  
  229. typedef struct composite_component_st AFMCompositeComponent;
  230.  
  231. struct composite_st
  232. {
  233.   AFMName name;
  234.   AFMInteger num_components;
  235.   AFMCompositeComponent *components;
  236. };
  237.  
  238. typedef struct composite_st AFMComposite;
  239.  
  240.  
  241. /**********************************************************************
  242.  *
  243.  *     Library API.
  244.  *
  245.  **********************************************************************/
  246.  
  247. /* Constants. */
  248.  
  249. #define UNITS_PER_POINT    1000
  250.  
  251. /* Successful operation. */
  252. #define AFM_SUCCESS    0
  253.  
  254. /*
  255.  * AFM information levels.  The AFM libarary returns always Global
  256.  * Font information, Writing Direction Metrics and Individual
  257.  * Character Metrics.  Other fields can be retrieved by defining some
  258.  * of the following flags to afm_open_{font, file}() functions.
  259.  */
  260. #define AFM_I_MINIMUM        0x00
  261. #define AFM_I_COMPOSITES    0x01
  262. #define AFM_I_KERN_PAIRS    0x02
  263. #define AFM_I_TRACK_KERNS    0x04
  264. #define AFM_I_ALL        0xffffffff
  265.  
  266. /*
  267.  * Flags for the encoding functions.
  268.  */
  269. #define AFM_ENCODE_ACCEPT_COMPOSITES    0x01
  270.  
  271. typedef unsigned int AFMError;
  272.  
  273. typedef struct afm_handle_st *AFMHandle;
  274.  
  275. /* Supported encoding types. */
  276. typedef enum
  277. {
  278.   AFM_ENCODING_DEFAULT,        /* Font's default encoding. */
  279.   AFM_ENCODING_LATIN1,        /* ISO-8859/1 */
  280.   AFM_ENCODING_LATIN2,        /* ISO-8859/2 */
  281.   AFM_ENCODING_LATIN3,        /* ISO-8859/3 */
  282.   AFM_ENCODING_IBMPC,        /* IBM PC */
  283.   AFM_ENCODING_ASCII,        /* 7 bit ASCII */
  284.   AFM_ENCODING_MAC,        /* Mac */
  285.   AFM_ENCODING_VMS,        /* VMS multinational */
  286.   AFM_ENCODING_HP8        /* HP Roman-8 */
  287. } AFMEncoding;
  288.  
  289. /* Special encoding types for individual characters. */
  290. #define AFM_ENC_NONE        ((void *) 0)
  291. #define AFM_ENC_NON_EXISTENT     ((void *) 1)
  292.  
  293.  
  294. /* AFM information for a single PostScript font. */
  295.  
  296. struct afm_font_st
  297. {
  298.   /* AFM Library's private data. */
  299.   struct afm_font_private_data_st *private;
  300.  
  301.   AFMNumber version;        /* AFM format specification version number. */
  302.   unsigned int info_level;
  303.  
  304.   /*
  305.    * Current font encoding.  Following values are valid:
  306.    *
  307.    *   AFM_ENC_NONE        character is not encoded
  308.    *   AFM_ENC_NON_EXISTENT    character is encoded, but font does not 
  309.    *                have the specified character
  310.    *   <pointer to character's metrics>
  311.    *                character is encoded and it exists in font
  312.    */
  313.   AFMIndividualCharacterMetrics *encoding[256];
  314.  
  315.   AFMGlobalFontInformation global_info;
  316.   AFMWritingDirectionMetrics writing_direction_metrics[2];
  317.  
  318.   AFMInteger num_character_metrics;
  319.   AFMIndividualCharacterMetrics *character_metrics;
  320.  
  321.   AFMInteger num_composites;
  322.   AFMComposite *composites;
  323.  
  324.   AFMInteger num_kern_pairs;
  325.   AFMPairWiseKerning *kern_pairs;
  326.  
  327.   AFMInteger num_track_kerns;
  328.   AFMTrackKern *track_kerns;
  329. };
  330.  
  331. typedef struct afm_font_st *AFMFont;
  332.  
  333.  
  334.  
  335. /*
  336.  * Prototypes for public functions.
  337.  */
  338.  
  339. /*
  340.  * Format error <error> to human readable format to buffer <buf>.
  341.  * Buffer must be long enough for error messages (256 bytes is good).
  342.  */
  343. void afm_error_to_string __P ((AFMError error, char *buf));
  344.  
  345. /*
  346.  * Open AFM library.  <path> specifies the search path for the AFM
  347.  * files.  A handle to the library is returned in <handle_return>.
  348.  */
  349. AFMError afm_create __P ((const char *path, unsigned int verbose_level,
  350.               AFMHandle *handle_return));
  351.  
  352. /*
  353.  * Close AFM library handle <handle>.
  354.  */
  355. AFMError afm_destroy __P ((AFMHandle handle));
  356.  
  357. /*
  358.  * Set AFM library's verbose level to <level>.  Value 0 means "no output".
  359.  */
  360. AFMError afm_set_verbose __P ((AFMHandle handle, unsigned int level));
  361.  
  362. /*
  363.  * Return a prefix to the font <fontname>'s data.  Various font
  364.  * resource file names can be constructed from the returned prefix:
  365.  *   AFM    <prefix>.afm
  366.  *   PFA    <prefix>.pfa
  367.  *
  368.  * Returned prefix belongs to AFM library, user should not modify it.
  369.  */
  370. AFMError afm_font_prefix __P ((AFMHandle handle, const char *fontname,
  371.                    const char **prefix_return));
  372.  
  373. /*
  374.  * Open font <name> and return font handle in <font_return>.
  375.  */
  376. AFMError afm_open_font __P ((AFMHandle handle, unsigned int info_level,
  377.                 const char *name, AFMFont *font_return));
  378.  
  379. /*
  380.  * Open AFM file <filename> and return font handle in <font_return>.
  381.  */
  382. AFMError afm_open_file __P ((AFMHandle handle, unsigned int info_level,
  383.                  const char *filename, AFMFont *font_return));
  384.  
  385. /*
  386.  * Open built-in default font (Courier).
  387.  */
  388. AFMError afm_open_default_font __P ((AFMHandle handle, AFMFont *font_return));
  389.  
  390. /*
  391.  * Close font <font>.
  392.  */
  393. AFMError afm_close_font __P ((AFMFont font));
  394.  
  395. /*
  396.  * Dump font information to file <fp>.
  397.  */
  398. void afm_font_dump __P ((FILE *fp, AFMFont font));
  399.  
  400. /*
  401.  * Return the width of the string <string, stringlen>.
  402.  */
  403. AFMError afm_font_stringwidth __P ((AFMFont font, AFMNumber ptsize,
  404.                     char *string, unsigned int stringlen,
  405.                     AFMNumber *w0x_return,
  406.                     AFMNumber *w0y_return));
  407.  
  408. /*
  409.  * Return the width of the character <ch>.
  410.  */
  411. AFMError afm_font_charwidth __P ((AFMFont font, AFMNumber ptsize,
  412.                   unsigned int ch, AFMNumber *w0x_return,
  413.                   AFMNumber *w0y_return));
  414.  
  415. /*
  416.  * Encode character code <code> to print as character <name>. 
  417.  * If <name> is NULL, encoding is removed.  <flags> can contain
  418.  * any combination of the AFM_ENCODE_* values.
  419.  */
  420. AFMError afm_font_encode __P ((AFMFont font, unsigned char code, char *name,
  421.                    unsigned int flags));
  422.  
  423. /*
  424.  * Apply encoding <enc> to font <font>.  <flags> can contain any 
  425.  * combination of the AFM_ENCODE_* values.
  426.  */
  427. AFMError afm_font_encoding __P ((AFMFont font, AFMEncoding enc,
  428.                  unsigned int flags));
  429.  
  430. #endif /* not AFM_H */
  431.